package com.demo.tankGame05;

import java.util.Vector;

/**
 * 自己的坦克 英雄
 *
 * @author gy
 * @date 2022/4/18
 */
public class Hero extends Tank {

    Shot shot = null;

    // 定义子弹的集合
    Vector<Shot> shots = new Vector<>();

    public Hero(int x, int y) {
        super(x, y);
    }

    public Hero(int x, int y, int speed) {
        super(x, y, speed);
    }

    public void shotEnemyTank() {

        // 控制子弹的数量，如果 数量超过5可就不再创建了
        if(shots.size() == 5){
            return;
        }

        // 创建 shot 对象，根据当前 Hero位置方向来创建 shot
        switch (getDirect()) {
            case 0:
                shot = new Shot(getX() + 20, getY(), 0);
                break;
            case 1:
                shot = new Shot(getX() + 60, getY() + 20, 1);
                break;
            case 2:
                shot = new Shot(getX() + 20, getY() + 60, 2);
                break;
            case 3:
                shot = new Shot(getX(), getY() + 20, 3);
                break;
            default:
        }
        //讲子弹加入到集合中
        shots.add(shot);

        // 启动我们的shot 线程
        Thread bulletThread = new Thread(shot);
        bulletThread.start();
    }
}
